package com.example.javastream.demo;

import java.util.stream.Stream;

public class LinkOps {
    public static void main(String[] args) {
        Stream<Integer> integerStream = Stream.of(1, 2, 3, 4, 5);
        // 保留为true的元素
        integerStream.filter(i -> i == 1).forEach(System.out::println);

        System.out.println("1=========================");
        integerStream = Stream.of(1, 2, 3, 4, 5);
        // 只保留两个
        integerStream.limit(2).forEach(System.out::println);

        System.out.println("2=========================");
        integerStream = Stream.of(1, 2, 2, 4, 5);
        // 基于equal方法去重
        integerStream.distinct().forEach(System.out::println);


        System.out.println("3=========================");
        integerStream = Stream.of(1, 2, 2, 4, 5);
        // 遍历元素
        integerStream.peek(System.out::println).forEach(System.out::println);
    }
}
